package com.ungao.framework.scanner;

import com.ungao.framework.annotation.Component;
import com.ungao.framework.annotation.Service;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class AnnotationScanner {

    /**
     * 容器自带注解
     */
    private final Set<Class<? extends Annotation>> containerAnnotations = new HashSet<>(16);

    /**
     * 外部扩展注解
     */
    private final Set<Class<? extends Annotation>> extendAnnotations = new HashSet<>(16);

    /**
     * 初始容器注解
     */
    public AnnotationScanner() {
        this.containerAnnotations.add(Service.class);
        this.containerAnnotations.add(Component.class);
    }

    /**
     * 存入外部扩展注解
     *
     * @param annotation
     * @return
     */
    public AnnotationScanner put(Class<? extends Annotation> annotation) {
        this.extendAnnotations.add(annotation);
        this.extendAnnotations.removeAll(this.containerAnnotations);
        return this;
    }

    /**
     * 存入外部扩展注解
     *
     * @param annotations
     * @return
     */
    public AnnotationScanner put(Collection<Class<? extends Annotation>> annotations) {
        this.extendAnnotations.addAll(annotations);
        this.extendAnnotations.removeAll(this.containerAnnotations);
        return this;
    }

    /**
     * 获取容器自带注解
     *
     * @return
     */
    public Collection<Class<? extends Annotation>> getContainers() {
        return Collections.unmodifiableCollection(this.containerAnnotations);
    }

    /**
     * 获取外部扩展注解
     *
     * @return
     */
    public Collection<Class<? extends Annotation>> getExtends() {
        return Collections.unmodifiableCollection(this.extendAnnotations);
    }
}
